<template>
	<view v-if="!isccccc">
		<u-navbar :is-back="true" title="问答"></u-navbar>
		<u-tabs :list="tablist" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<view class="VerticalBox" v-if="current==0">
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation :style="[{'height':viewitwm}]"
				:scroll-into-view="'main-'+mainCur" @scroll="VerticalMain">
				<view class="" v-for="(item,index) in list" :key="index" :id="'main-'+index">
					<view class="cu-list">
						<view class="cu-item" @click="detail(item.liQuestions)">
							<view class="qes flex">
								<image src="../../static/img/sign-question.png" mode="widthFix" style="width: 42rpx;">
								</image>
								<view style="width: calc(100% - 42rpx);">{{item.liQuestions.content}}</view>
							</view>
							<view class="ans text-gray flex">
								<image src="../../static/img/sign-answer.png" mode="widthFix"
									style="width: 42rpx;top:0;"></image>
								<view style="width: calc(100% - 42rpx);">{{item.content}}</view>
							</view>
							<view class="fuhao" >
								<text
									style="font-size: 20rpx;margin-right: 10rpx;">问题发布于{{formatDate(item.liQuestions.createTime)}}</text>
								<u-icon name="eye" color="#2979ff" size="32"></u-icon>
								<text class="margin-right">{{item.chakannum?item.chakannum:0}}</text>
								<!-- <view>
									<text class="cuIcon-attention text-grey"></text>
									<text class="margin-right">{{item.eye}}</text>
									<text class="cuIcon-attention text-grey"></text>
									<text class="margin-right">{{item.like}}</text>
									<text class="cuIcon-attention text-grey"></text>
									<text>{{item.comment}}</text>
								</view> -->
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="VerticalBox" v-if="current==1">
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation :style="[{'height':viewitwm}]"
				:scroll-into-view="'main-'+mainCur" @scroll="VerticalMain">
				<view class="" v-for="(item,index) in zdlist" :key="index" :id="'main-'+index">
					<view class="cu-list">
						<view class="cu-item" @click="detail(item)">
							<view class="qes flex">
								<image src="../../static/img/sign-question.png" mode="widthFix" style="width: 42rpx;">
								</image>
								<view style="width: calc(100% - 42rpx);">{{item.content}}</view>
							</view>
							<view class="ans text-gray flex">
								<image src="../../static/img/sign-answer.png" mode="widthFix"
									style="width: 42rpx;top:0;"></image>
								<view style="width: calc(100% - 42rpx);">{{item.detail?item.detail.content:"暂未回答"}}</view>
							</view>
							<view class="fuhao" >
								<text
									style="font-size: 20rpx;margin-right: 10rpx;">问题发布于{{formatDate(item.createTime)}}</text>
								<u-icon name="eye" color="#2979ff" size="32"></u-icon>
								<text class="margin-right">{{item.chakannum?item.chakannum:0}}</text>
								<!-- <view>
									<text class="cuIcon-attention text-grey"></text>
									<text class="margin-right">{{item.eye}}</text>
									<text class="cuIcon-attention text-grey"></text>
									<text class="margin-right">{{item.like}}</text>
									<text class="cuIcon-attention text-grey"></text>
									<text>{{item.comment}}</text>
								</view> -->
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getTeachInfo,
		getTeachList,
		getGoodsCollection,
		deleteGoodsCollection,
		deleteStoreCollection,
	} from "@/api/members.js";
	import moment from 'dayjs';
	import {
		http,
		Method
	} from "@/utils/request.js";
	import storage from "@/utils/storage.js";
	export default {
		data() {
			return {
				isccccc:false,
				tablist: [{
					name: '我的回答'
				}, {
					name: '待我回答'
				}],
				current: 0,
				total: 0,
				page: 1,
				zdpage: 1,
				pagesize: 10,
				viewitwm: 0,
				list: [],
				// list: [{
				// 		"id": 1,
				// 		"qes": "我们单位买了一辆车，原价值26万，已计提折旧14万，卖价为4万，公司要求要做转账...",
				// 		"ans": "1.固定资产转入清理：借：累计折旧 固定资产减值准备（如计提）固定资产清理贷：固定资产原值报...",
				// 		time: "20小时前发布",
				// 		eye: 10,
				// 		like: 200,
				// 		comment: 21,
				// 	},
				// 	{
				// 		"id": 2,
				// 		"qes": "我们单位买了一辆车，原价值26万，已计提折旧14万，卖价为4万，公司要求要做转账...",
				// 		"ans": "1.固定资产转入清理：借：累计折旧 固定资产减值准备（如计提）固定资产清理贷：固定资产原值报...",
				// 		time: "20小时前发布",
				// 		eye: 10,
				// 		like: 200,
				// 		comment: 21,
				// 	},
				// ],
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				load: true,
				title: "推荐问答",
				zdlist:[],
				zdtotal:0,
			};
		},
		onLoad() {
			let systemInfo = uni.getSystemInfoSync();
			let statusBarHeight = systemInfo.windowHeight - (systemInfo.statusBarHeight + uni.upx2px(88)) - 10-uni.upx2px(80);
			this.viewitwm = statusBarHeight + "px";
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			this.getMy()
			this.getZhidingMy()
		},
		onShow() {
			this.isccccc = uni.getStorageSync("isccccc");
			let that = this;
			if (this.$options.filters.isLogin("auth")) {
				// this.dataList()
			} else {
				uni.showModal({
					title: "提示",
					content: "检测到您的账号还未登录,是否去登录？",
					confirmColor: this.$lightColor,
					success: function(res) {
						if (res.confirm) {
							that.$options.filters.navigateToLogin();
						} else if (res.cancel) {
							uni.navigateBack();
						}
					},
				});
			}

		},
		onReady() {
			uni.hideLoading()
		},
		methods: {
			change(index) {
				this.current = index;
				
			},
			formatDate(longtime) {
				return moment(longtime).format("YYYY-MM-DD HH:mm:ss")
			},
			detail(obj) {
				uni.navigateTo({
					url: "/pages/verticalnav/question-detail?id=" + obj.id,
				})
			},
			async getZhidingMy() {
				let user = storage.getUserInfo();
				let params = {
					pageNumber: this.zdpage,
					pageSize: this.pagesize,
					appointUser: user.id
				}
				let res = await http.request({
					url: "/lili/liQuestions/zhidingwodehuida",
					method: Method.GET,
					needToken: true,
					params
				});
				this.zdtotal = res.data.result.total;
				let records = res.data.result.records || [];
				// records = records.filter(item => {
				// 	return item.liQuestions;
				// })
				this.zdlist = this.zdlist.concat(records)
			
			},
			
			async getMy() {
				let user = storage.getUserInfo();
				let params = {
					pageNumber: this.page,
					pageSize: this.pagesize,
					userId: user.id
				}
				let res = await http.request({
					url: "/lili/liQuestionsDetail/wodehuida",
					method: Method.GET,
					needToken: true,
					params
				});
				this.total = res.data.result.total;
				let records = res.data.result.records || [];
				records = records.filter(item => {
					return item.liQuestions;
				})
				this.list = this.list.concat(records)

			},
			
			TabSelect(e) {
				this.tabCur = e.currentTarget.dataset.id;
				this.mainCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 70
			},
			VerticalMain(e) {
				// #ifdef MP-ALIPAY
				return false //支付宝小程序暂时不支持双向联动 
				// #endif
				let that = this;
				let tabHeight = 0;
				if (this.load) {
					for (let i = 0; i < this.list.length; i++) {
						let view = uni.createSelectorQuery().select("#main-" + this.list[i].id);
						view.fields({
							size: true
						}, data => {
							this.list[i].top = tabHeight;
							tabHeight = tabHeight + data.height;
							this.list[i].bottom = tabHeight;
						}).exec();
					}
					this.load = false
				}
				let scrollTop = e.detail.scrollTop + 10;
				for (let i = 0; i < this.list.length; i++) {
					if (scrollTop > this.list[i].top && scrollTop < this.list[i].bottom) {
						this.verticalNavTop = (this.list[i].id - 1) * 70
						this.tabCur = this.list[i].id
						console.log(scrollTop)
						return false
					}
				}
			},
			detail(obj, index) {
				uni.navigateTo({
					url: "/pages/verticalnav/question-detail?id=" + obj.id,
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
		background-color: #F1F2F3;
	}

	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;

		margin: 0;
		border: none;
		height: 70px;
		position: relative;

		.logo {
			width: 40rpx;
			height: 40rpx;
			margin-top: 30rpx;
		}
	}

	/deep/.nav .cu-item {
		line-height: 30rpx;
	}

	.VerticalNav.nav .cu-item.cur {
		background-color: #ffffff;
	}

	.VerticalNav.nav .cu-item.cur::after {
		content: "";
		width: 8upx;
		height: 100%;
		position: absolute;
		background-color: #FF9240;
		top: 0;
		left: 0upx;
		bottom: 0;

	}

	.VerticalBox {
		display: flex;
	}

	.VerticalMain {
		background-color: #ffffff;
		flex: 1;
		padding: 0 30rpx;

		.cu-list {
			color: #666666;
			font-size: 26rpx;
			line-height: 30rpx;

			.cu-item {
				padding: 20rpx 0;
				border-bottom: 1rpx solid #DBDDE0;

				image {
					width: 70rpx;
					height: 32rpx;
					position: relative;
					top: 8rpx;
					margin-right: 15rpx;
				}

				.qes {
					font-size: 28rpx;
					font-weight: 550;

					line-height: 50rpx;
				}

				.ans {
					margin: 20rpx 0;
				}

				.fuhao {
					margin-left: 42rpx;
					color: #999999;
					display: flex;
					justify-items: center;
					align-items: flex-end;
					justify-content: flex-end;
					.margin-right {
						margin: 0 20rpx 0 10rpx;
					}
				}
			}
		}
	}


	.text-gray {
		color: #888888;
	}
</style>
